package com.azdebugit.list.arraylist.test.option.test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class StudentA {
    private String userName;
    private List<String> courses;

    public StudentA(String userName, List<String> courses) {
        this.userName = userName;
        this.courses = courses;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void addCourse(String course) {
        courses.add(course);
    }

    public boolean removeCourse(String course) {
        return courses.remove(courses);

    }

    public List<String> getCourses() {
        return Collections.unmodifiableList(courses);
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("数学");
        list.add("语文");
        StudentA s = new StudentA("lily", list);

        List<String> anotherList = s.getCourses();

        /**
         * throws java.lang.UnsupportedOperationException should replace with
         * s.addCourse(String course)
         */
        s.addCourse("物理");
        System.out.println("lily's course.length = " + s.getCourses().size());
        anotherList.add("英语");

        // 不会走到这一步，因为上边抛出了异常
        System.out.println("lily's course.length = " + s.getCourses().size());
    }
}